<?php
/**
 *
 * Shoe Model
 * @author Dennis, Denis, Simon
 *
 */
class Shoe_model extends CI_Model {
	/**
	 * Constructor
	 *
	 */
	function Shoe_model()
	{
		$this->load->database();
	}
	/**
	 *
	 * Returns all shoes stored in the db
	 */
	function getAllShoes()
	{
		//Query the data table for every record and row
		$query = $this->db->get('shoe');
			
		if ($query->num_rows() < 1)
		{
			//show_error('Database is empty!');
		}else{
			return $query->result();
		}
	}

	/**
	 *
	 * Returns all brookes shoes stored in the db
	 */
	function getAllBrooksShoes(){
		//Query the data table for every record and row with custom shoes
		$query = $this->db->get_where('shoe', array('IsCustom' => 0));

		if ($query->num_rows() < 1)
		{
			//show_error('Database is empty!');
		}else{
			return $query->result();
		}
	}

	/**
	 *
	 * Returns all custom shoes stored in the db
	 */
	function getAllCustomShoes()
	{
		//Query the data table for every record and row with custom shoes
		$query = $this->db->get_where('shoe', array('IsCustom' => 1));

		if ($query->num_rows() < 1)
		{
			//show_error('Database is empty!');
		}else{
			return $query->result();
		}
	}
	/**
	 *
	 * returns a shoe by id
	 * @param $id ID of the shoe
	 */
	function getShoe($id)
	{
		$query = $this->db->get_where('shoe', array('ID' => $id));

		if ($query->num_rows() < 1)
		{
			//show_error('Database is empty!');
		}else{
			return $query->row();
		}
	}
	/**
	 *
	 * returns a shoe by modell name
	 * @param $id ID of the shoe
	 */
	function getShoeByModell($modell)
	{
		$query = $this->db->get_where('shoe', array('Modell' => $modell));
			
		if ($query->num_rows() < 1)
		{
			//show_error('Database is empty!');
		}else{
			return $query->row();
		}
	}
	/**
	 *
	 * storees new shoe in DB
	 * @param  $modell Modell of the shoe
	 * @param  $manufactor Manufactor
	 * @param  $runeffort runeffort
	 */
	function addShoe($modell,$manufactor,$runeffort, $isCustom)
	{
		$data = array(
	   'Modell' => $modell,
	   'Manufactor' => $manufactor,
	   'RunEffort' => $runeffort,
	   'IsCustom' => $isCustom
		);

		return $this->db->insert('shoe', $data);
	}
	/**
	 *
	 * storees new shoe in DB
	 * @param  $modell Modell of the shoe
	 * @param  $manufactor Manufactor
	 * @param  $runeffort runeffort
	 */
	function updateShoe($id, $modell,$manufactor,$runeffort)
	{
		$data = array(
		   'Modell' => $modell,
		   'Manufactor' => $manufactor,
		   'RunEffort' => $runeffort
		);

		$this->db->where('ID', $id);
		return $this->db->update('shoe', $data);
	}
	/**
	 *
	 * deletes a shoe
	 * @param  $id Shoe ID
	 */
	function deleteShoe($id)
	{
		$this->db->delete('shoe', array('ID' => $id));
	}

}
?>